home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1997 November / Macworld (1997-11).dmg / Inside Macworld / Reviews / BeyondPress™ 3.0.1 Eval / BeyondPress Extras / Scripting Extras / Scripts&Master Elements ReadMe
Text File  |  1996-04-01  |  3KB  |  68 lines

  1. Embedding Scripts in Master Elements ReadMe 
  2. BeyondPress lets you embed Apple Events scripts in master elements. Each time you export the article, the script is executed. Examples of scripts embedded in master elements include:
  3.  
  4.    •  A script that references a text file that is common to all your Web pages. When you export an article containing this master element, the script will insert the current version of that text file. 
  5.  
  6.    •  A script that finds a price from a database. When you export an article containing this master element, the script will insert the current price from the database.
  7.  
  8.    •  A script that provides an alternative to the Date and/or Time master elements. If you export your articles before you post the Web pages, you could run a script that post-dates the exported pages.
  9.  
  10.  
  11. Embedding a Script in a Master Element
  12.  
  13.    1.  Create a folder called "$" in your QuarkXPress folder; place the scripts you're planning to embed in the $ folder.
  14.  
  15.    2.  In Master Elements Preferences, create a new master element or edit an existing one.
  16.  
  17.    3.  In the HTML Text field of the Edit Master Element dialog box, enter the script referencing information as follows:
  18.  
  19.       •    enclose the information in brackets { }
  20.       • enter a $ sign immediately followed by the name of the script file
  21.       • enter the name of any function called
  22.       • enter the parameter for the function in parentheses and quotes
  23.  
  24.       For example:
  25.  
  26.       {$SampleScript include("some file name")} 
  27.  
  28.       The data returned must be a text string. A sample script is shown below.
  29.  
  30.    4.  Export the article to execute the script.
  31.  
  32. Sample Script 
  33. This script locates a text file and inserts it in a master element when you export an article. You can paste the script below into your Script Editor to give it a try. 
  34.  
  35. ----------------------------------------------------------------------------------------
  36. --
  37. -- parentfolder
  38. --
  39. -- given a file path, return the path to the containing folder
  40. --
  41. ----------------------------------------------------------------------------------------
  42. on parentfolder(fpath)
  43.     set txtoff to offset of ":" in ((reverse of (every character of fpath)) as text)
  44.     set pathsize to count of characters in fpath
  45.     text from character 1 to character (pathsize - txtoff + 1) of fpath
  46. end parentfolder
  47.  
  48. ----------------------------------------------------------------------------------------
  49. --
  50. -- include
  51. --
  52. -- include the text of a file with the given name, located within the element scripts folder, into the
  53. -- HTML output
  54. --
  55. ----------------------------------------------------------------------------------------
  56. on include given data:fileName, reference:elementReference
  57.     try
  58.         set filePath to parentfolder(path to current application as text) & "$:" & fileName
  59.         set fRefNum to open for access file filePath
  60.         set fileLength to (get eof fRefNum)
  61.         set fileData to read fRefNum to fileLength
  62.         close access fRefNum
  63.         return fileData
  64.     on error
  65.         return "File Not Found"
  66.     end try
  67. end include
  68.